#!/usr/bin/python
# -*- coding: UTF-8 -*-
#Python 2.7.12
import sys
import os
import struct

#print '参数个数为:',len(sys.argv);
#print '参数列表：', str(sys.argv);
print "target file:"
print "        ", sys.argv[1]
update_img = open(sys.argv[1], 'wb+')
bytes = struct.pack('B',0)

for i in range(2, len(sys.argv)):
    print "--------adding", sys.argv[i]
    file_size = os.path.getsize(sys.argv[i])
    complete_num = (512 - file_size % 512)
    #print('0x%x'%complete_num)
    f = open(sys.argv[i], 'rb')
    update_img.write(f.read())
    #512字节对齐
    for j in range(0, complete_num):
	    update_img.write(bytes)
    f.close

update_img.close()
print "finish all!"

